<template>
	<view class="content">
		<view class="title">注册</view>
		<view class="list">
			<view class="list_line">手机号码</view>
			<view class="list_cont">
				<image class="login_icon" src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/phone.png" mode=""></image>
				<view class="list_input">
					<input type="number" placeholder="请输入手机号码" class="input" placeholder-class="place" maxlength="11" v-model="phone" />
				</view>
			</view>
		</view>
		<view class="list">
			<view class="list_line">验证码</view>
			<view class="list_cont">
				<image class="login_icon" src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/code.png" mode=""></image>
				<view class="list_code">
					<view class="reg_fl">
						<input type="number" placeholder="请输入验证码" class="input_code" placeholder-class="place"  v-model="code" />
					</view>
					<view class="reg_fr">
						<button class="phone_code " @tap="getCode" :disabled="disabled">{{timeText}}</button>
					</view>
				</view>
			</view>
		</view>
		<view class="list">
			<view class="list_line">登录密码</view>
			<view class="list_cont">
				<image class="login_icon" src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/password.png" mode=""></image>
				<view class="list_input">
					<input type="password" placeholder="请设置登录密码" class="input" placeholder-class="place" v-model="password" />
				</view>
			</view>
		</view>
		<view class="list">
			<view class="list_line">填写邀请码</view>
			<view class="list_cont">
				<image class="login_icon" src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/invitation.png" mode=""></image>
				<view class="list_input">
					<input type="password" placeholder="请输入邀请码" class="input" placeholder-class="place" v-model="referralCode" />
				</view>
			</view>
		</view>
		<view class="formBtn" @click="register">注册</view>
		<view class="bot_handle">
			<view class="bot_register" @click="login">已有账号？<text class="proctol">立即登录</text></view>
		</view>
	</view>
</template>

<script>
	import api from "../../../../common/api/api.js"
	export default {
		data() {
			return {
				phone:'',
				password:'',
				code:'',
				disabled:false,
				timeText:'获取验证码',
				countdown:60,
				referralCode:''
				
			}
		},
		methods: {
			// 登陆
			login: function () {
				uni.navigateTo({
					url:"../login"
				})
			},
			// 获取验证码
			getCode: function () {
				var that = this;
				var mobile = that.phone;
				if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(mobile))){ 
					uni.showToast({
						title: '手机号格式不正确',
						icon:"none",
						duration:2000
					});
					return false; 
				} 
				api.getVerifyCode({
					phone:mobile,
					type:'register'
				}).then(res => {
					console.log(res,"====")
					uni.showToast({
						title:res.msg,
						icon:"none"
					})
					that.setTime();
				})
				
				
			},
			// 倒计时
			setTime:function(){
				var that = this;
				var time = that.countdown;
				if(time == 0){
					that.timeText = "获取验证码";
					that.disabled = false;
					time = 60; 
					that.countdown = time;
					return
				}else{
					that.disabled = true
					var timea = time-1;
					//console.log(timea)
					that.countdown = timea
					that.timeText = '等待'+'('+timea+')秒';
				}
				setTimeout(function(){
					that.setTime()
				},1000)
			},
			// 注册
			register: function () {
				let that = this;
				if (that.phone == '') {
					uni.showToast({
						title:'请输入账号',
						icon:"none"
					})
					return
				} else if (that.code == '') {
					uni.showToast({
						title:'请输入验证码',
						icon:"none"
					})
					return
				} else if (that.password == '') {
					uni.showToast({
						title:'请设置登录密码',
						icon:"none"
					})
					
					return
				} 
				api.getUserRegister({
					account:that.phone,
					captcha:that.code,
					password:that.password,
					referralCode:that.referralCode
				}).then(res => {
					console.log(res,"注册")
					
					uni.showToast({
						title:res.msg,
						icon:"none"
					})
					setTimeout(function () {
						uni.navigateBack({
							delta: 1
						});
					},1500)
				})
				
				
				
			},
			
			
			
		}
	}
</script>

<style lang="less">
	page {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 100rpx 70rpx 0rpx 70rpx;
		letter-spacing: 3rpx;
	}
	.content {
		width: 100%;
		box-sizing: border-box;
		color: #333333;
	}
	button {
		border: none;
		resize: none;
		padding: 0;
	}
	button::after {
		border: none;
		resize: none;
		padding: 0;
	}
	.title {
		width: 100%;
		box-sizing: border-box;
		font-size: 68rpx;
		line-height: 98rpx;
		padding: 30rpx 0;
	}
	.list {
		width: 100%;
		box-sizing: border-box;
		margin-bottom: 14rpx;
		.list_line {
			width: 100%;
			box-sizing: border-box;
			font-size: 28rpx;
			line-height: 80rpx;
		}
		.list_cont {
			width: 100%;
			box-sizing: border-box;
			border: 1rpx solid #DDDDDD;
			border-radius: 8rpx;
			padding: 12rpx 30rpx;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			.login_icon {
				width: 50rpx;
				height: 50rpx;
			}
			.list_input {
				width: calc(100% - 70rpx);
				box-sizing: border-box;
				padding-left: 30rpx;
				.input {
					width: 100%;
					height: 70rpx;
					line-height: 70rpx;
					font-size: 36rpx;
				}
				.place {
					font-size: 30rpx;
					color: #999999;
				}
			}
			.list_code {
				width: calc(100% - 70rpx);
				box-sizing: border-box;
				padding-left: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.reg_fr {
					width: 195rpx;
					box-sizing: border-box;
					margin: 0;
					.phone_code {
						width: 100%;
						font-size: 30rpx;
						height: 70rpx;
						line-height: 70rpx;
						color: #E42221;
						background: none;
						padding: 0;
					}
				}
				.reg_fl {
					width: calc(100% - 195rpx);
					box-sizing: border-box;
					padding-right: 5rpx;
					.input {
						width: 100%;
						height: 70rpx;
						line-height: 70rpx;
						font-size: 36rpx;
					}
					.place {
						font-size: 30rpx;
						color: #999999;
					}
				}
			}
		
		}
	}
	
	.formBtn {
		width: 100%;
		box-sizing: border-box;
		text-align: center;
		line-height: 94rpx;
		border-radius: 8rpx;
		background: #E42221;
		margin: 64rpx 0 30rpx 0;
		color: #FFFFFF;
		font-size: 30rpx;
	}
	.bot_handle {
		width: 100%;
		box-sizing: border-box;
		font-size: 24rpx;
		line-height: 33rpx;
		text-align: center;
		.proctol {
			color: #E42221;
		}
	}

</style>
